/**
 * @file   Packet.h
 * @author Djuro Drljaca (djurodrljaca@gmail.com)
 * @date   2013-03-11
 * @brief  DataBus Packet.
 *
 * Copyright (C) 2013  Djuro Drljaca <djurodrljaca@gmail.com>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 *
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library.  If not, see <http://www.gnu.org/licenses/>.
 */

#ifndef LIBDATABUS_COMMON_PACKET_H
#define LIBDATABUS_COMMON_PACKET_H

#include <DataBus/Common/PacketHeader.h>
#include <DataBus/Common/PacketPayload.h>

namespace DataBus
{
/**
 * @brief The Packet class
 */
class DATABUSSHARED_EXPORT Packet
{
public:
    /**
     * @brief Constructor for Packet
     */
    Packet();

    /**
     * @brief Constructor for Packet from a packet header and payload
     *
     * @param packetHeader      Packet header
     * @param packetPayload     Packet payload
     */
    Packet(const PacketHeader &packetHeader,
           const PacketPayload &packetPayload);

    /**
     * @brief Descructor for Packet
     */
    ~Packet();

    /**
     * @brief Reads the packet header
     *
     * @return Packet header
     */
    PacketHeader getHeader() const;

    /**
     * @brief Reads the packet payload
     *
     * @return Packet header
     */
    PacketPayload getPayload() const;

    /**
     * @brief Reads the source of the communication (Client ID)
     *
     * @return Source Client ID
     */
    quint8 getSource() const;

    /**
     * @brief Sets the source of the communication (Client ID)
     *
     * @param source    Source Client ID
     */
    void setSource(const quint8 source);

    /**
     * @brief Reads the destination of the communication (Client ID)
     *
     * @return Destination Client ID
     */
    quint8 getDestination() const;

    /**
     * @brief Sets the destination of the communication (Client ID)
     *
     * @param destination   Destination Client ID
     */
    void setDestination(const quint8 destination);

    /**
     * @brief Reads the packet type
     *
     * @return Packet type
     */
    PacketType getPacketType() const;

    /**
     * @brief Sets the packet type
     *
     * @oaram packetType    Packet type
     */
    void setPacketType(const PacketType packetType);

    /**
     * @brief Reads the packet ID
     *
     * @return Packet ID
     */
    quint8 getPacketId() const;

    /**
     * @brief Set the packet ID
     *
     * @param packetId  Packet ID
     */
    void setPacketId(const quint8 packetId);

    /**
     * @brief Reads the payload size
     *
     * @return Payload size in bytes
     */
    quint8 getPayloadSize() const;

    /**
     * @brief Reads the payload data
     *
     * @return Payload data
     */
    QByteArray getData() const;

    /**
     * @brief Set the payload length
     *
     * @param data  Payload data
     */
    void setData(const QByteArray &data);

    /**
     * @brief Convert packet to byte array
     *
     * @return Byte array with packet
     */
    QByteArray toBinary() const;

protected:
    /**
     * @brief Packet header
     */
    PacketHeader m_packetHeader;

    /**
     * @brief Packet payload
     */
    PacketPayload m_packetPayload;
};
}

#endif // LIBDATABUS_COMMON_PACKET_H
